package cn.fl.ref.bscrateinfo.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.ref.bscrateinfo.service.IBscRateInfoService;
import cn.fl.ref.bscrateinfo.transform.BscRateInfoVOTransform;
import cn.fl.ref.bscrateinfo.vo.BscRateInfoVO;
import fl.ref.bscrateinfo.condition.BscRateInfoQueryCondition;
import fl.ref.bscrateinfo.dto.BscRateInfoDTO;
import fl.ref.bscrateinfo.service.IBscRateInfoApiService;

/**
 * @Description: 基础利率信息
 */
@Service
public class BscRateInfoServiceImpl implements IBscRateInfoService {

	private static final Logger logger = LoggerFactory.getLogger(IBscRateInfoService.class);

	@Autowired
	private IBscRateInfoApiService bscRateInfoApiService;

	@Override
	public BscRateInfoVO selectById(Long id) throws BaseException {
		if (StringUtils.isEmpty(id)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		BscRateInfoDTO dto = this.bscRateInfoApiService.selectById(id);
		return BscRateInfoVOTransform.toVO(dto);
	}

	@Override
	public Long add(BscRateInfoVO entity) throws BaseException {
		if (null == entity) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		// 系统日志-有用户的情况下
		BaseLogUtils.info(logger, "add", "新增BscRateInfo数据.", CurrentThreadContext.getCurrentUserName());

		// 系统日志-无用户的情况下
		BaseLogUtils.info(logger, "add", "新增BscRateInfo数据.");
		return this.bscRateInfoApiService.add(BscRateInfoVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException {
		if (StringUtils.isEmpty(id)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		return this.bscRateInfoApiService.removeById(id);
	}

	@Override
	public boolean modify(BscRateInfoVO entity) throws BaseException {
		if (null == entity) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		return this.bscRateInfoApiService.modify(BscRateInfoVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException {
		if (null == page)
			page = new Pager();
		return this.bscRateInfoApiService.searchListPage(page);
	}

	@Override
	public List<BscRateInfoVO> searchList(BscRateInfoQueryCondition condition) {
		return BscRateInfoVOTransform.toVOList(this.bscRateInfoApiService.searchList(condition));
	}

}
